<?php

class Collections {

	private function __construct(){}
	
	public static function sum($arr1,$arr2,$flag = false) {
		if( !is_array($arr1) || !is_array($arr2) )
			return array();
		foreach( $arr2 as $key_arr2 => $value_arr2 )
			if( array_key_exists($key_arr2, $arr1) )
				if( $flag ){
					if( is_numeric($arr1[$key_arr2]) && is_numeric($arr2[$key_arr2]) )
						$arr1[$key_arr2] = $arr1[$key_arr2]+$arr2[$key_arr2];
					else 
						$arr1[$key_arr2] .= "++".$arr2[$key_arr2];
				}else{
					$arr1[$key_arr2] = $value_arr2;
				}
			else if( $flag )
				$arr1[$key_arr2] = $value_arr2;
		return $arr1;
	}
	
	public static function subtraction($arr1,$arr2,$flag = false) {
		if( !is_array($arr1) || !is_array($arr2) )
			return array();
		foreach( $arr2 as $key_arr2 => $value_arr2 )
			if( array_key_exists($key_arr2, $arr1) )
				if( $flag ){
					if( is_numeric($arr1[$key_arr2]) && is_numeric($arr2[$key_arr2]) )
						$arr1[$key_arr2] = $arr1[$key_arr2]-$arr2[$key_arr2];
					else 
						$arr1[$key_arr2] .= "--".$arr2[$key_arr2];
				}else{
					unset($arr1[$key_arr2]);
				}
		return $arr1;
	}
	
	public static function removePerKey(&$arr,$key) {
		$responseArray = array();
		$response = "";
		foreach ($arr as $keyNow => $valueNow)
			if( $key != $keyNow )
				$responseArray[ $keyNow ] = $valueNow;
			else 
				$response = $valueNow;
		$arr = $responseArray;
		return $response;
	}
	
}

?>